#@embedLayout()


#define content()

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:true">
        <div id="vendorDatagridId"></div>

        <div id="vendorDatagridTb">
            <div class="row">
                <div class="col-md-12">
                    <form id="vendorSearchForm">
                        <div class="easyui-panel" style="width:100%;padding:10px;"
                             data-options="iconCls:'icon-application_form'">

                            厂商名称: <input class="easyui-textbox" id="vendorName"
                                         style="width:200px">&nbsp;&nbsp;
                            厂商别名: <input class="easyui-textbox" id="vendorAlias"
                                         style="width:200px">&nbsp;&nbsp;

                            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true"
                               onclick="vendorDatagridQuery();"
                               iconCls="icon-zoom">#(_res.get('system.common.search'))</a>
                            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true"
                               onclick="$('#vendorSearchForm').form('clear');"
                               iconCls="icon-zoom_out">#(_res.get('system.common.clear'))</a>
                        </div>
                    </form>
                </div>
                <div class="row">
                    <div class="col-md-12" style="padding: 5px 25px;">
                        <a href="javascript:;" class="easyui-linkbutton"
                           data-options="iconCls:'icon-application_add',plain:true"
                           id="vendorAdd">增加厂商</a>

                        <a href="javascript:;" class="easyui-linkbutton"
                           data-options="iconCls:'icon-application_edit',plain:true"
                           id="vendorEdit">编辑厂商</a>

                        <a href="javascript:;" class="easyui-linkbutton"
                           data-options="iconCls:'icon-application_delete',plain:true"
                           id="vendorRemove">删除厂商</a>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

#end


#define css()


#end


#define js()

<script type="text/javascript">
    var vendorDatagridId = "vendorDatagridId", vendorFormId = "vendorFormId", vendorDatagridTb = "vendorDatagridTb";
    var vendorDatagridListUrl = contextRootPath + '/equipment/vendorList';

    $(function () {
        //初始化表格
        $("#" + vendorDatagridId).datagrid({
            url: vendorDatagridListUrl,
            fit: true,
            border: false,
            rownumbers: true,
            pageSize: 30,
            toolbar: '#' + vendorDatagridTb,
            singleSelect: false,
            pagination: true,
            nowrap: false,
            striped: true,
            fitColumns: true,
            columns: [[
                {field: DBConts.TABLE_VENDOR.VEN_ID, title: DBConts.TABLE_VENDOR.VEN_ID, width: 100, checkbox: true},
                {
                    field: DBConts.TABLE_VENDOR.VENDOR_NAME,
                    title: '厂商名称',
                    sortable: true
                }, {
                    field: DBConts.TABLE_VENDOR.VENDOR_ALIAS,
                    title: '厂商别名',
                    sortable: true
                }
            ]]
        });


        $("#vendorAdd").on('click', function () {
            var params = {};
            params.dlgId = 'vendor_crud_dlg';
            params.title = '增加厂商';
            params.width = 700;
            params.height = 250;
            params.top = '40px';
            params.modal = true;
            params.iconCls = 'icon-shape_ungroup';
            params.url = contextRootPath + '/equipment/vendorAdd';
            params.buttons = [{
                text: '提交',
                iconCls: 'icon-application_go',
                handler: function () {
                    vendor_datagrid_save('add');
                }
            }, {
                text: '重置',
                iconCls: 'icon-application_side_contract',
                handler: function () {
                    clearForm('vendorFormId')
                }
            }];

            crud_dlg(params);
        });


        $("#vendorEdit").on('click', function () {
            var selected = $('#' + vendorDatagridId).datagrid('getSelected');

            if (selected === null) {
                $.messager.alert("提示框", "请选择需要操作的厂商!", "warning");
                return;
            }

            var selections = $('#' + vendorDatagridId).datagrid('getSelections');

            if (selections.length < 1) {
                $.messager.alert("提示框", "请选择需要操作的厂商!", "warning");
                return;
            } else if (selections.length > 1) {
                $.messager.alert("提示框", "编辑的厂商为多个，请重新选择!", "warning");
                return;
            }

            var params = {};
            params.dlgId = 'vendor_crud_dlg';
            params.title = '编辑厂商';
            params.width = 700;
            params.height = 250;
            params.top = '40px';
            params.modal = true;
            params.iconCls = 'icon-application_edit';
            params.url = contextRootPath + '/equipment/vendorEdit/' + selected[DBConts.TABLE_VENDOR.VEN_ID];
            params.buttons = [{
                text: '提交',
                iconCls: 'icon-application_go',
                handler: function () {
                    vendor_datagrid_save();
                }
            }, {
                text: '关闭',
                iconCls: 'icon-application_side_contract',
                handler: function () {
                    $('#vendor_crud_dlg').dialog('close');
                }
            }];

            crud_dlg(params);
        });


        $("#vendorRemove").on('click', function () {
            var selections = $('#' + vendorDatagridId).datagrid('getSelections');
            var ids = "";
            var names = "";

            if (selections.length < 1) {
                $.messager.alert("提示框", "请选择需要操作的厂商!", "warning");
                return;
            }

            $.messager.confirm('确认框', '请确定需要删除所选择的厂商么？', function (r) {
                if (r) {
                    $.each(selections, function (i, v) {
                        ids += v[DBConts.TABLE_VENDOR.VEN_ID] + ",";
                        names += v[DBConts.TABLE_VENDOR.VENDOR_NAME] + ",";
                    });

                    $.post(contextRootPath + "/equipment/vendorRemove?venId=" + ids + "&vendorName=" + names, function (data) {
                        var params = {};
                        params.element = vendorDatagridId;
                        params.data = data;
                        params.isClose = false;
                        resultCallback(params);
                    }, 'json');
                }
            });

        });
    });


    function vendorDatagridQuery() {
        var vendorName = $("#vendorName");
        var vendorAlias = $("#vendorAlias");

        var flag = $("#vendorSearchForm").form('enableValidation').form('validate');
        if (!flag) return;

        $("#" + vendorDatagridId).datagrid({
            queryParams: {
                "vendor.vendor_name": vendorName.val(),
                "vendor.vendor_alias": vendorAlias.val()
            }
        });
    }


</script>

#end


